package com.mldong.modules.sys.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.mldong.base.CommonPage;
import com.mldong.base.CommonResult;
import com.mldong.base.IdParam;
import com.mldong.base.IdsParam;
import com.mldong.modules.sys.dto.TaskExecutionHistoryPageParam;
import com.mldong.modules.sys.dto.TaskExecutionHistoryParam;
import com.mldong.modules.sys.service.TaskExecutionHistoryService;
import com.mldong.modules.sys.vo.TaskExecutionHistoryVO;
import com.mldong.validation.Groups;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
    * 已完成任务的历史归档 前端控制器
    * </p>
*
* @author mldong
* @since 2025-10-12
*/
@RestController
@Api(tags = "已完成任务的历史归档管理")
@RequiredArgsConstructor
public class TaskExecutionHistoryController {
    private final TaskExecutionHistoryService taskExecutionHistoryService;
    /**
     * 添加已完成任务的历史归档
     * @param param
     * @return
     */
    @PostMapping("/sys/taskExecutionHistory/save")
    @ApiOperation(value = "添加已完成任务的历史归档")
    @SaCheckPermission("sys:taskExecutionHistory:save")
    public CommonResult<?> save(@RequestBody @Validated({Groups.Save.class}) TaskExecutionHistoryParam param) {
        taskExecutionHistoryService.save(param);
        return CommonResult.ok();
    }
    /**
     * 删除已完成任务的历史归档
     * @param param
     * @return
     */
    @PostMapping("/sys/taskExecutionHistory/remove")
    @ApiOperation(value = "删除已完成任务的历史归档")
    @SaCheckPermission("sys:taskExecutionHistory:remove")
    public CommonResult<?> remove(@RequestBody IdsParam param) {
        taskExecutionHistoryService.removeBatchByIds(param.getIds());
        return CommonResult.ok();
    }
    /**
     * 修改已完成任务的历史归档
     * @param param
     * @return
     */
    @PostMapping("/sys/taskExecutionHistory/update")
    @ApiOperation(value = "修改已完成任务的历史归档")
    @SaCheckPermission("sys:taskExecutionHistory:update")
    public CommonResult<?> update(@RequestBody @Validated({Groups.Update.class}) TaskExecutionHistoryParam param) {
        taskExecutionHistoryService.update(param);
        return CommonResult.ok();
    }
    /**
     * 查询单个已完成任务的历史归档
     * @param param
     * @return
     */
    @PostMapping("/sys/taskExecutionHistory/detail")
    @ApiOperation(value = "查询单个已完成任务的历史归档")
    @SaCheckPermission("sys:taskExecutionHistory:detail")
    public CommonResult<TaskExecutionHistoryVO> detail(@RequestBody IdParam param) {
        TaskExecutionHistoryVO taskExecutionHistory = taskExecutionHistoryService.findById(param.getId());
        return CommonResult.data(taskExecutionHistory);
    }
    /**
     *分页查询已完成任务的历史归档列表
     * @param param
     * @return
     */
    @PostMapping("/sys/taskExecutionHistory/page")
    @ApiOperation(value = "分页查询已完成任务的历史归档列表")
    @SaCheckPermission("sys:taskExecutionHistory:page")
    public CommonResult<CommonPage<TaskExecutionHistoryVO>> page(@RequestBody TaskExecutionHistoryPageParam param) {
        return CommonResult.data(taskExecutionHistoryService.page(param));
    }
}
